package com.example.bzh.gamecat.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.example.bzh.gamecat.R;
import com.example.bzh.gamecat.base.BaseActivity;
import com.example.bzh.gamecat.ui.live.LiveFragment;
import com.example.bzh.gamecat.ui.message.MessageFragment;
import com.example.bzh.gamecat.ui.society.SocietyFragment;
import com.example.bzh.gamecat.ui.cattery.CatteryFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.smssdk.SMSSDK;
import cn.jpush.android.api.JPushInterface;

public class MainActivity extends BaseActivity {


    @BindView(R.id.frame_continer_main)
    FrameLayout frameContinerMain;
    @BindView(R.id.image_message)
    ImageView imageMessage;
    @BindView(R.id.image_society)
    ImageView imageSociety;
    @BindView(R.id.image_live)
    ImageView imageLive;
    @BindView(R.id.image_cattery)
    ImageView imageCattery;
    private FragmentManager manager;
    private MessageFragment messageFragment;
    private SocietyFragment societyFragment;
    private LiveFragment liveFragment;
    private CatteryFragment catteryFragment;

    public static final int SELECTED_MESSAGE = 0;
    public static final int SELECTED_SOCIETY = 1;
    public static final int SELECTED_LIVE = 2;
    public static final int SELECTED_CATTERY = 3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SMSSDK.initSDK(this, "1616d9212b6a1", "789fce3f8208236d3ca9f25966a9b015");
        ButterKnife.bind(this);
//        1616d9212b6a1
        JPushInterface.init(this);
  //      SMSSDK.initSDK(this, "1616d9212b6a1", "789fce3f8208236d3ca9f25966a9b015");

//        1616d9212b6a1
        selectFragment(SELECTED_MESSAGE);
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public void initView() {
        super.initView();
        manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        messageFragment = new MessageFragment();
        societyFragment = new SocietyFragment();
        liveFragment = new LiveFragment();
        catteryFragment = new CatteryFragment();
        transaction.add(R.id.frame_continer_main, messageFragment);
        transaction.add(R.id.frame_continer_main, societyFragment);
        transaction.add(R.id.frame_continer_main, liveFragment);
        transaction.add(R.id.frame_continer_main, catteryFragment);
        transaction.commit();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    public void setButtonSelected() {
        imageMessage.setSelected(false);
        imageSociety.setSelected(false);
        imageLive.setSelected(false);
        imageCattery.setSelected(false);
    }

    public void selectFragment(int position) {
        setButtonSelected();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.hide(messageFragment).hide(societyFragment).hide(liveFragment).hide(catteryFragment);
        switch (position) {
            case SELECTED_MESSAGE:
                fragmentTransaction.show(messageFragment);
                imageMessage.setSelected(true);
                break;
            case SELECTED_SOCIETY:
                fragmentTransaction.show(societyFragment);
                imageSociety.setSelected(true);
                break;
            case SELECTED_LIVE:
                fragmentTransaction.show(liveFragment);
                imageLive.setSelected(true);
                break;
            case SELECTED_CATTERY:
                fragmentTransaction.show(catteryFragment);
                imageCattery.setSelected(true);
                break;
        }
        fragmentTransaction.commit();
    }


    @OnClick({R.id.relative_message, R.id.relative_society, R.id.relative_live, R.id.relative_cattery})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.relative_message:
                selectFragment(SELECTED_MESSAGE);
                break;
            case R.id.relative_society:
                selectFragment(SELECTED_SOCIETY);
                break;
            case R.id.relative_live:
                selectFragment(SELECTED_LIVE);
                break;
            case R.id.relative_cattery:
                selectFragment(SELECTED_CATTERY);
                break;
        }
    }
}
